/**
 * 查找文件路径
 */
import common from '../../tnxet-common.js';
import util from '../main-util.js';

export default {
    name: common.event.file.findPath,
    listen(dir, pathRegex) {
        return new Promise((resolve, reject) => {
            if (dir) {
                dir = util.file.getAbsolutePathBasedOnApp(dir);
                let all = [];
                if (util.file.loopDir(dir, pathRegex, filePath => {
                    all.push(filePath);
                })) {
                    resolve(all);
                } else {
                    reject(dir + ' is not a directory');
                }
            } else {
                reject('dir is ' + dir);
            }
        });
    },
}
